package com.sneakxy.mybatis.commons.repository.config;

import java.util.List;

import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.springframework.data.domain.Slice;

import com.sneakxy.mybatis.commons.repository.query.MybatisPageTempImpl;

/**
 * @author 潜行的青衣
 */
public class MybatisCommonsObjectFactory extends DefaultObjectFactory {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4359287498361928658L;
	
	private static MybatisCommonsObjectFactory mybatisCommonsObjectFactory = new MybatisCommonsObjectFactory();
	
	public static MybatisCommonsObjectFactory getMybatisCommonsObjectFactory() {
		return mybatisCommonsObjectFactory;
	}

	@Override
	public <T> boolean isCollection(Class<T> type) {
		return Slice.class.isAssignableFrom(type) || super.isCollection(type);
	}

	@Override
	public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
		return super.create(type, constructorArgTypes, constructorArgs);
	}

	@Override
	protected Class<?> resolveInterface(Class<?> type) {
		if(Slice.class.isAssignableFrom(type)) {
			return MybatisPageTempImpl.class;
		}
		return super.resolveInterface(type);
	}

}
